<template>
  <div class="container">
    <div class="show">
      <div class="new_div">
<!--    <el-card class="box-card">-->
    <el-form ref="form" :model="form" label-width="80px" class="el-from">
      <h1 style="text-align: center;padding-top: 10px;">{{form.name}}</h1>
      <div style="padding: 20px;margin-bottom: 10px">{{form.description}}</div>
      <!--      <el-form-item label="时间">
              <el-col :span="11">
                <el-time-picker placeholder="选择时间" v-model="form.date" style="width: 100%;"></el-time-picker>
              </el-col>
            </el-form-item>-->
      <el-form-item class="lll"  >
      <el-button type="primary" @click="getId">开始答题</el-button>
      <el-button type="primary" @click="show">显示答卷</el-button>
        <el-button type="primary" @click="determine">确定提交</el-button>
        </el-form-item>
      <el-form-item label="答者账号">
        <el-input class="input" v-model="answerName" ></el-input>
      </el-form-item>
      <!-- 遍历已创建的选项渲染 -->
      <div class="ill" v-for="(item, index) in questItem" :key="index">
        <el-form-item :label="(index+1)+''" >
          <div class="item_title">
            <span>、{{ typeMap[item.type] }}: </span>
            <span v-text="item.title"></span>
          </div>
          <!-- 单项填空 -->
          <div v-if="item.type==='input'">
            <el-input class="disabled" placeholder="请输入答案.."  type="textarea" :rows="2" v-model="input"></el-input>
          </div>
          <div v-if="item.type==='radio'">
<!--            <el-radio-group v-model="radio">-->
           <div class="warp" v-if="item.options!==''">
            <el-radio v-model="radio[index]" label="1">{{''}}</el-radio>
              <p class="input" >{{'A .'+item.options}}</p>
           </div>
          <div class="warp" v-if="item.options2!==null">
            <el-radio v-model="radio[index]" label="2" >{{''}}</el-radio>
            <p class="input" >{{'B .'+item.options2}}</p>
          </div>
          <div class="warp" v-if="item.options3!==null">
            <el-radio v-model="radio[index]" label="3">{{''}}</el-radio>
            <p class="input" >{{'C .'+item.options3}}</p>
          </div>
          <div class="warp" v-if="item.options4!==null">
            <el-radio v-model="radio[index]" label="4">{{''}}</el-radio>
            <p class="input" >{{'D .'+item.options4}}</p>
          </div>
<!--          </el-radio-group>-->
          </div>
          <div v-if="item.type==='checkbox'">
            <el-checkbox-group v-model="checkList">
            <div class="warp" v-if="item.options!==null">
              <el-checkbox label="1">{{'A .'+item.options}}</el-checkbox>
<!--              <p class="input" >{{'A .'+item.options}}</p>-->
            </div>
            <div class="warp" v-if="item.options2!==null">
              <el-checkbox  :label="'B.'">{{'B .'+item.options2}}</el-checkbox>
            </div>
            <div class="warp" v-if="item.options3!==null">
              <el-checkbox  :label="'C.'">{{'C .'+item.options3}}</el-checkbox>
            </div>
            <div class="warp" v-if="item.options4!==null">
              <el-checkbox :label="'D.'">{{'D .'+item.options4}}</el-checkbox>
            </div>
          </el-checkbox-group>
          </div>
<!--          &lt;!&ndash; 多选 &ndash;&gt;-->
<!--          <div v-else-if="item.type==='checkbox'">-->
<!--            <div class="warp" v-for="(elm, i) in item.textList" :key="i">-->
<!--              <el-checkbox :label="(i+1)+'、'"></el-checkbox>-->
<!--              <el-input v-model="item.textList[i]"></el-input>-->
<!--            </div>-->
<!--          </div>-->

<!--          &lt;!&ndash; 选择填空 &ndash;&gt;-->
<!--          <div v-else-if="item.type === 'select'">-->
<!--            <el-select v-model="value" placeholder="请选择">-->
<!--              <el-option-->
<!--                v-for="(elm, i) in item.textList" :key="i"-->
<!--                :label="item.textList[i]"-->
<!--                :value="i+''">-->
<!--              </el-option>-->
<!--            </el-select>-->
<!--          </div>-->

          <!-- 矩阵填空 -->
<!--          <div v-else-if="item.type==='matrix'">-->
<!--            <div class="warp" v-for="(elm, i) in item.textList" :key="i">-->
<!--              <span> {{ item.textList[i] }}：</span>-->
<!--              <el-input class="disabled" placeholder="禁止输入" disabled></el-input>-->
<!--            </div>-->
<!--          </div>-->
          <!-- 上移、下移、删除 -->
        </el-form-item>
      </div>
    </el-form>
<!--    </el-card>-->
        </div>
      </div>
    </div>
</template>
<script>
// import previewQuestion from './previewQuestion'

export default {
  // components: {
  //   previewQuestion: previewQuestion
  // },
  created () {
    this.form.name = this.$route.query.title
    this.form.description = this.$route.query.description
    this.form.id = this.$route.query.id
    this.nid = this.$route.query.id
  },
  data () {
    return {
      value: '',
      matrixsNum: 1,
      num: 1,
      nid: 1,
      form: {
        itemList: [],
        description: '',
        name: '',
        date: '',
        id: 1
      },
      itemTitle: '',
      itemText: new Array(1),
      questItem: {},
      showItem: false,
      typeMap: {
        radio: '单选',
        checkbox: '多选',
        input: '问答'
      },
      nnn: 1,
      editIndex: '',
      radio: [],
      checkList: [],
      input: '',
      answerid: '',
      answerName: '',
      currentid: ''
    }
  },
  methods: {
    // 确定将选项添加进列表中进行渲染
    getId () {
      this.$http.get('/questionnaire/getId').then(({ data }) => {
        this.nnn = data.data
        console.log(this.nnn)
      })
    },
    show () {
      console.log(this.nid)
      if (this.nid === 666) {
        this.$http.get(`/questionnaire/preview/${this.nnn}`).then(({ data }) => {
          this.questItem = data.data
          console.log(data.data)
          console.log(this.form.id)
        })
      } else {
        this.$http.get(`/questionnaire/preview/${this.form.id}`).then(({ data }) => {
          this.questItem = data.data
          console.log(data.data)
        })
      }
      if (this.nid === 666) {
        this.currentid = this.nnn
      } else {
        this.currentid = this.form.id
      }
      console.log(this.currentid)
    },
    determine () {
      this.$http.get(`/getIdByName/${this.answerName}`).then(({ data }) => {
        this.answerid = data.data
        // console.log(data.data)
      })
      this.$http.post('/replyTb/add', {
        content: '',
        quesId: '',
        questionnaireId: this.currentid,
        replierId: this.answerid
      }).then(({ data }) => {
        if (data.code === 200) {
          this.$message.success('答卷提交成功！')
          // location.reload()
        } else {
          this.$message.error('答卷提交失败！')
        }
      })
    }
  }
}
</script>
<style lang="less" scoped>
.container{
  background: url(./1.png);
  height:2000px;
}
.warp {
  display: flex;
  align-items: center;
  margin-top:5px;
  margin-bottom:5px;
}
.lll{
  //margin: 0
  margin-bottom:15px;
}
.disabled {
  background: #F5F7FA;
  width: 650px;
}
.show{
  background: url(./1.png);
  background-repeat: repeat-y;
  width: 100%;
  //margin: auto;
  //position: absolute;
  //top: 0; left: 0; bottom: 0; right: 0;
}
.ill{
  //margin-bottom:10px;
}
.el-from{
  //margin: auto;
  //margin: auto;
  //position: absolute;
  //top: 0; left: 0; bottom: 0; right: 0;
  position:relative;
  //justify-content:center;
  //align-items:center;
}
.input {
  //-webkit-appearance: none;
  //background-color: #FFF;
  //background-image: none;
  //border-radius: 4px;
  //border: 1px solid #DCDFE6;
  //box-sizing: border-box;
  //color: #606266;
  //font-size: inherit;
  //height: 40px;
  //line-height: 40px;
  //outline: 0;
  //padding: 0 15px;
  //transition: border-color .2s cubic-bezier(.645, .045, .355, 1);
  //margin: 10px 0 0;
  width: 250px;
  height: 20px;
  display: block;
  margin-top:3px;
  margin-bottom:3px;
  //margin-block-start: 1em;
  //margin-block-end: 1em;
  //margin-inline-start: 0px;
  //margin-inline-end: 0px;
  padding-bottom:15px
}
.new_div {
  position: relative;
  top: 10px;
  left: 1%;
  width: 53%;
  height: 2000px;
  margin-left: 25%;
  background-color: #fff;
}
.el-radio {
  color: #606266;
  cursor: pointer;
  margin-right: 0;
}
</style>
